package com.OA.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.OA.dao.BulletinDao_clz;
import com.OA.entity.BulletinNoticeInformation;
import com.OA.entity.Menu_clz;
import com.OA.entity.Role_clz;
import com.OA.service.BulletionService_clz;
import com.OA.util.Page;

/**
 * 公告管理的服务层的实现层
 * @author clz
 *
 */
@Service
public class BulletionServiceImpl_clz implements BulletionService_clz{

	@Autowired
	BulletinDao_clz bulletinDao_clz;
	
	
	/**
	 * 公告管理普通员工的分页查询
	 * @param page
	 * @param category
	 * @return
	 */
	@Override
	public Page<BulletinNoticeInformation> selectBulletionByCategory(Page<BulletinNoticeInformation> page,
			String category,Date firstD,Date nextD ,String title) {
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		map.put("page",page);
		map.put("beginIndex",(page.getPageNo()-1)*page.getPageSize());
		map.put("pageSize",page.getPageSize());
		map.put("category", category);
		if (title != null) {
			map.put("title", "%"+title+"%");
		}else {
			map.put("title", null);
		}
		map.put("firstD", firstD);
		map.put("nextD",nextD);
		
		List<BulletinNoticeInformation> list = bulletinDao_clz.selectBulletionByCategory(map);
		
		page.setRows(list);
		
		map.put("page",null);
		list = bulletinDao_clz.selectBulletionByCategory(map);
		page.setTotal(list.size());
		
		return page;
	}
	
	/**
	 * 查询公告页面的内容
	 * @param title
	 * @return
	 */
	@Override
	public BulletinNoticeInformation bulletionContent(int bn_id) {
		BulletinNoticeInformation bulletinNoticeInformation  = bulletinDao_clz.bulletionContent(bn_id);
		return bulletinNoticeInformation;
	}
	
	/**
	 * 通过用户id查看名字
	 * @param userId
	 * @return
	 */
	@Override
	public String userNameById(int userId) {
		String userName = bulletinDao_clz.userNameById(userId);
		return userName;
	}

	/**
	 * 通过userId查询数据形成树形菜单
	 * @param userId
	 * @return
	 */
	@Override
	public List<Menu_clz> bulletinTreeMenuByUserId(Integer userId) {
		List<Menu_clz> list = bulletinDao_clz.bulletinTreeMenuByUserId(userId);
		return list;
	}

	/**
	 * 插入数据
	 * @param menu
	 */
	@Override
	public void saveMenu(Menu_clz menu) {
		bulletinDao_clz.saveMenu(menu);
	}
	
	
	/**
	 * 通过菜单名字查询菜单id
	 * @param menuname
	 * @return
	 */
	@Override
	public int menuIdByMenuName(String menuname) {
		List<Menu_clz> list = bulletinDao_clz.menuIdByMenuName(menuname);
		return list.get(list.size()-1).getMenuid();
	}

	/**
	 * 查看所有的角色
	 * @return
	 */
	@Override
	public List<Role_clz> selectAllRole() {
		return bulletinDao_clz.selectAllRole();
	}
	
	/**
	 * 插入角色菜单关系表
	 * @return
	 */
	@Override
	public void insectRolemenu(int roleid, int menuid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleid", roleid);
		map.put("menuid", menuid);
		
		bulletinDao_clz.insectRolemenu(map);
	}

	
	/**
	 * 通过菜单id查询菜单
	 * @param menuid
	 * @return
	 */
	@Override
	public Menu_clz menuByMenuId(Integer menuid) {
		return bulletinDao_clz.menuByMenuId(menuid);
	}
	
	/**
	 * 通过菜单的id查看菜单 回填数据
	 * @param menu
	 */
	@Override
	public void updataMenu(Menu_clz menu) {
		bulletinDao_clz.updataMenu(menu);
	}

	/**
	 * 删除菜单
	 */
	@Override
	public void removeMenu(Integer menuid) {
		bulletinDao_clz.removeMenu(menuid);
	}

	/**
	 * 删除角色菜单关系表
	 */
	@Override
	public void removeRoleMenu(Integer menuid) {
		bulletinDao_clz.removeRoleMenu(menuid);
	}

	/**
	 * 获取所有的子节点
	 * @param menuparentld
	 * @return
	 */
	public List<Menu_clz> MenuByMenuparentld(Integer menuparentld){
		return bulletinDao_clz.MenuByMenuparentld(menuparentld);
	}

	/**
	 * 删除
	 */
	@Override
	public void remove(Integer bn_id) {
		bulletinDao_clz.remove(bn_id);		
	}

	/**
	 * 插入公告
	 * @param bulletinNoticeInformation
	 */
	@Override
	public void insertBulletinNoticeInformation(BulletinNoticeInformation bulletinNoticeInformation) {
		bulletinDao_clz.insertBulletinNoticeInformation(bulletinNoticeInformation);
		
	}
	/**
	 * 修改公告
	 * @param bulletinNoticeInformation
	 */
	@Override
	public void updateBulletinNoticeInformation(BulletinNoticeInformation bulletinNoticeInformation) {
		bulletinDao_clz.updateBulletinNoticeInformation(bulletinNoticeInformation);
		
	}
}
